//便捷处理输入参数与回调
const default_out = {
    data() {
        return {
            table_visible: true,
        };
    },


    methods: {
        option_table_model() {
            return []
        },
        set_table_model(config, modelPath) {
            if (!modelPath) modelPath = 'option.table.model'
            _.set(this, modelPath, this.init_table_model(config))
            // this.option.table.model = this.init_table_model(config)
        },

        init_table_model(config) {
            config = Object.assign({
                dataType: 'current',
                filterAttrs: false,
                optionObj: null,
            }, config)
            let out_option = this.option_table_model()
            //读取当前应用的配置
            if (config.dataType == 'current') {
                let _currentOption = null
                if (config.optionObj) {
                    _currentOption = config.optionObj
                } else {
                    const localOption = localStorage.getItem(this.$route.path)
                    if (localOption) _currentOption = JSON.parse(localOption)
                }
                if (_currentOption) {
                    out_option = out_option.map(realit => {
                        let currit = _.find(_currentOption, it => realit.key ? (realit.key == it.key) : (realit.type == it.type))
                        return Object.assign({}, realit, currit)
                    })
                }
            }
            //配置应用默认值
            out_option.forEach(it => {
                if (it.type || it.keyShow == undefined) it.keyShow = true
                if (it.keyShowForce) {
                    it.keyShow = true
                }
            })


            if (config.filterAttrs == true) {
                out_option = out_option.map(it => _.pick(it, ['key', 'label','type', 'fixed', 'keyShow','keySort','keyShowForce']))
            } else {
                out_option = out_option.filter(it => it.type || it.keyShow != false)
                    .sort((ita, itb) => ita.keySort - itb.keySort)

                let expandDescItem = _.find(out_option, it => it.type == 'expandDesc')
                if (expandDescItem) {
                    expandDescItem.expandDesc.model = out_option.filter(it => !it.type && it.keyShow == 'expandDesc')
                    if (_.isEmpty(expandDescItem.expandDesc.model)) {
                        expandDescItem.keyShow = false
                    }
                }
                out_option = out_option.filter(it => it.keyShow == undefined || it.keyShow == true)

                out_option.forEach(it => {
                    delete it.keySort
                    delete it.keyGroup
                    delete it.keyShow
                    delete it.keyShowForce
                })
                if (expandDescItem) {
                    expandDescItem.expandDesc.model.forEach(it => {
                        delete it.keySort
                        delete it.keyGroup
                        delete it.keyShow
                        delete it.keyShowForce
                    })
                }
                //.map(it => _.omit(it, ['keyGroup', 'keyShow']))
            }
            return out_option
        },
        change_table_model(e, path, modelPath) {
            if (e) {
                localStorage.setItem(path, JSON.stringify(e))
                this.set_table_model({ optionObj: e }, modelPath)
            } else {
                localStorage.removeItem(path)
                this.set_table_model(null, modelPath)
            }

            this.refresh_table_visible()
        },

        refresh_table_visible() {

            const table = this.getSuperTablePage()
            if (table) {
                this.$set(table, 'inner_visible', false)

                this.$nextTick(() => {
                    if (table) {
                        this.$set(table, 'inner_visible', true)
                    }
                })
            }

        },
    }
}
export default default_out